<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>${empty diary ? '写新日记' : '编辑日记'}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            background: #f5f5f5;
        }
        .edit-container {
            background: white;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 1.5rem;
        }
        label {
            display: block;
            margin-bottom: 0.5rem;
            color: #333;
            font-weight: bold;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        textarea {
            height: 300px;
            resize: vertical;
        }
        .submit-btn {
            background: #007bff;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .submit-btn:hover {
            background: #0056b3;
        }
    </style>
</head>
<body>
<div class="edit-container">
    <h1>${empty diary ? '写新日记' : '编辑日记'}</h1>
    <form action="${pageContext.request.contextPath}/diary" method="post">
        <input type="hidden" name="action" value="${empty diary ? 'create' : 'update'}">
        <c:if test="${not empty diary}">
            <input type="hidden" name="id" value="${diary.id}">
        </c:if>

        <div class="form-group">
            <label>标题：</label>
            <input type="text"
                   name="title"
                   value="${diary.title}"
                   required
                   placeholder="请输入日记标题">
        </div>

        <div class="form-group">
            <label>内容：</label>
            <textarea name="content"
                      required
                      placeholder="写下你的心情...">${diary.content}</textarea>
        </div>

        <button type="submit" class="submit-btn">
            ${empty diary ? '保存日记' : '更新日记'}
        </button>
        <%-- 修正返回链接 --%>
        <a href="${pageContext.request.contextPath}/home.jsp"
           style="margin-left: 20px; color: #666;">取消</a>
    </form>
</div>
</body>
</html>
